;
(function (window, angular) {
    'use strict';
    angular.module("Controller.Personal.PersonalInfo", [])
        .controller("PersonalInfoCtrl", ["$scope", "$state", "ybWidget", "ybHttp", "MESG_TYPE", function ($scope, $state, ybWidget, ybHttp, MESG_TYPE) {
            $scope.submitted = false;
            $scope.detailInfo = {};

            function getUserInfo() {
                var service = "auth";
                var reqUrl = "/profile/getLogin";
                ybHttp.Get(service, reqUrl).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return;
                    }
                    $scope.detailInfo = resp.value;
                });
            }

            $scope.saveData = function (isValid) {
                if (!isValid) {
                    $scope.submitted = true;
                    return;
                }
                var service = "auth";
                var reqUrl = "/profile/update";
                var param = {};
                param.name = $scope.detailInfo.name;
                param.email = $scope.detailInfo.email;
                param.mobile = $scope.detailInfo.mobile;
                ybHttp.Post(service, reqUrl, param).then(function (resp) {
                    if (resp.code !== 0) {
                        ybWidget.ShowMessage(resp, MESG_TYPE.Error);
                        return false;
                    }
                    ybWidget.ShowToaster('success', '操作成功');
                    getUserInfo();
                    $scope.submitted = false;
                });
            };

            $scope.resetData = function () {
                getUserInfo();
            };
            
            (function () {
                getUserInfo();
            })();
        }])
    ;
})(window, window.angular);